<script setup lang="ts">
import {ref,reactive,shallowRef,shallowReactive,computed} from "vue"

const num=ref(0)
//computed默认调用get只读方法
const parity=computed(function(){
  return num.value%2===0 ? "偶数":"奇数"
})
const twice=computed(function(){
  return num.value*2
})
//computed调用get只读方法，set改变数据方法
const changeNum=computed({
  get(){
    return num
  },
  set(val:any){
    num.value=val
  }
})
function change(){
  num.value=200
}
</script>

<template>
  <div>
    <input type="number" v-model="num">
    <div>判断为偶数还是奇数：{{ parity }}</div>
    <div>输出为二倍：{{ twice }}</div>
    <button @click="change">改变num</button>
  </div>
</template>

<style scoped>

</style>
